package blackjack.client;

import java.util.ArrayList;
import java.util.Random;


public class CardDeck{

	static int c = 0;
	int summa;
	@SuppressWarnings("unchecked")
	public static ArrayList cards = new ArrayList();

	public CardDeck(){
		if(c == 0)addCards();
		c++;
	}

	public synchronized String getCard(){
		Random r = new Random();
		int i = r.nextInt(cards.size());
		String result;                       
		result = (String)cards.get(i);               
		cards.remove(i);                   
		return result;                    
	}

	@SuppressWarnings("unchecked")
	public void addCards(){
		cards.clear();
		String[] suits = new String[]{"ri", "a", "p", "ru"};
		for(String suit : suits){
			for (int cardNr = 2; cardNr <= 4; cardNr++){
				String s = cardNr + "." + suit;
				cards.add(s);
			}
		}
		for(String suit : suits){
			for (int cardNr = 6; cardNr <= 9; cardNr++){
				String s = cardNr + "." + suit;
				cards.add(s);
			}
		}
		for(String suit : suits){
			for (int cardNr = 10; cardNr <= 11; cardNr++){
				String s = cardNr + suit;
				cards.add(s);
			}
		}
	}

	public int CardStringtoInt(String card){
		int charValue = 0;
		int realValue = 0;

		if(card.charAt(1)=='.'){
			charValue = card.charAt(0);
			realValue=Character.getNumericValue(charValue);
		}else if(card.charAt(1)=='0'){
			realValue=10;
		}else{
			realValue=11;
		}
		return realValue;
	}
}
